﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

[RequireComponent(typeof(Graphic))]
[AddComponentMenu("UI/UISineColor")]
public class UISineColor : SineBase
{

    public Color targetColor = Color.red;
    public Color currentColor = Color.white;

    public Graphic graphic;


    private void Awake()
    {
        this.AfterInit();
        graphic = this.GetComponent<Graphic>();
    }

    protected override void AfterInit()
    {
        this.GetComponent<SpriteRenderer>();

        this.magnitude = 1.0f;
        this.initialValue = this.magnitude / 2;
        this.periodOffset = -this.period / 2;
        this.lastKnownValue = this.initialValue;
    }


    protected override void UpdateFromPhase(float value)
    {
        this.graphic.color = Color.Lerp(this.currentColor, this.targetColor, (value + 1) / 2);
    }

}
